<!-- src/components/RoomList.vue -->
<template>
  <div>
    <ul class="room-list">
      <li
        v-for="room in rooms"
        :key="room.id"
        class="room-item"
        @click="joinRoom(room.id)"
      >
        {{ room.name }} ({{ room.players.length }} 玩家)
      </li>
    </ul>
  </div>
</template>

<script setup>
import { defineProps } from 'vue';

const props = defineProps({
  rooms: {
    type: Array,
    required: true,
  },
});

const emit = defineEmits(['join-room']);

function joinRoom(roomId) {
  emit('join-room', roomId);
}
</script>

<style scoped>
.room-list {
  list-style: none;
  padding: 0;
}

.room-item {
  cursor: pointer;
  padding: 10px;
  border: 1px solid #ccc;
  margin: 5px 0;
  background-color: #f9f9f9;
  border-radius: 5px;
}

.room-item:hover {
  background-color: #e0e0e0;
}
</style>
